package servlets;

import dao.DrugDAO;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * Сервлет, используемый для удаления строк из таблицы
 *
 * @author Andrey Murgo
 */
public class DeleteRowController extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        DrugDAO dao = new DrugDAO();
        dao.deleteDrug(Integer.parseInt(req.getParameter("id")));
        String previous = req.getParameter("previous");
        req.setAttribute("deleteResult", "ok");
        req.setAttribute("previousEvent", "delete");
        if (previous != null && previous.equals("search")) {
            req.getRequestDispatcher("search.do").forward(req, resp);
        } else {
            req.getRequestDispatcher("view.do").forward(req, resp);
        }
    }
}
